<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="throttle">throttle</button>

    <script>
        let el = document.getElementById('throttle');
        el.addEventListener('click', throttle(sayHello))

        function throttle(fn) {
            let canRun = true;
            return function () {
                if (!canRun) {
                    return;
                }

                canRun = false;

                setTimeout(() => {
                    fn.apply(this, arguments);
                    canRun = true;
                }, 1000)
            }
        }

        function sayHello() {
            console.log("Hello")
        }
    </script>
</body>

</html>